# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.

from odoo import api, fields, models, _


class MrpWorkorder(models.Model):
    _inherit = 'mrp.workorder'

    workorder_sum = fields.Many2one('mrp.workorder.sum', string='Workorder Sum')

    @api.constrains('state', 'product_id', 'workcenter_id')
    def _link_cancel_workorder_sum(self):
        sum_model = self.env['mrp.workorder.sum']
        for rec in self:
            if rec.state == 'cancel':
                rec.workorder_sum = False
            else:
                sum_model._create_or_update_workorder_sum(rec)
